package com.epower.dao.epowerword.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.ali.luna.commons.dao.BaseDAOImpl;
import com.epower.dao.epowerword.EpowerWordDAO;
import com.epower.dataobject.EpowerWordDO;

/***
 * DAO实现层
 * 
 * @author QuickDev
 * 
 */
@Scope("singleton")
@Component("epowerWordDAO")
public class EpowerWordDAOImpl extends BaseDAOImpl implements EpowerWordDAO {
	/***
	 * 查询单个对象
	 */
	@Override
	public EpowerWordDO getEpowerWordByOption(EpowerWordDO epowerWord) {
		return (EpowerWordDO) getSqlMapClientTemplate().queryForObject("EpowerWordDAOImpl.GET-EPOWERWORD-BY-OPTION", epowerWord);
	}

	/***
	 * 查询对象列表
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<EpowerWordDO> getEpowerWordListByOption(EpowerWordDO epowerWord) {
		return super.executeQueryForList("EpowerWordDAOImpl.GET-EPOWERWORDList-BY-OPTION", "EpowerWordDAOImpl.GET-EPOWERWORD-COUNT-BY-OPTION", epowerWord);

	}

	/***
	 * 根据id查询对象
	 */
	@Override
	public EpowerWordDO getEpowerWordById(Integer id) {
		return (EpowerWordDO) getSqlMapClientTemplate().queryForObject("EpowerWordDAOImpl.GET-EPOWERWORD-BY-ID", id);
	}

	/***
	 * 删除操作
	 */
	@Override
	public boolean deleteEpowerWordById(Integer id) {
		int num = getSqlMapClientTemplate().update("EpowerWordDAOImpl.DELETE-EPOWERWORD-BY-ID", id);
		return num == 0 ? false : true;
	}

	/***
	 * 查询数量
	 */
	@Override
	public Integer getEpowerWordCountByOption(EpowerWordDO epowerWord) {
		return (Integer) getSqlMapClientTemplate().queryForObject("EpowerWordDAOImpl.GET-EPOWERWORD-COUNT-BY-OPTION", epowerWord);
	}

	/***
	 * 更新操作
	 */
	@Override
	public boolean updateEpowerWordByOption(EpowerWordDO epowerWord) {
		int num = getSqlMapClientTemplate().update("EpowerWordDAOImpl.UPDATE-EPOWERWORD-BY-OPTION", epowerWord);
		return num == 0 ? false : true;
	}

	/***
	 * 添加操作
	 * 
	 * @param
	 * @return
	 */
	@Override
	public Integer addEpowerWord(EpowerWordDO epowerWord) {
		return (Integer) getSqlMapClientTemplate().insert("EpowerWordDAOImpl.ADD-EPOWERWORD", epowerWord);
	}

    @Override
    public EpowerWordDO getWordByBookid(int bookid, int index) {
        Map<String,Integer> paramers = new HashMap<String,Integer>();
        paramers.put("bookid", bookid);
        paramers.put("index", index);
        return (EpowerWordDO)getSqlMapClientTemplate().queryForObject("EpowerWordDAOImpl.GET-EPOWERWORD-BY-BOOKID",paramers);
    }

    @Override
    public int getWordCountByBookid(int bookid) {
        return (Integer)getSqlMapClientTemplate().queryForObject("EpowerWordDAOImpl.GET-EPOWERWORD-COUNT-BY-BOOKID",bookid);
    }

}